package com.hotel.controllers;

import com.hotel.entitys.RestPOJO;
import com.hotel.entitys.Staff;
import com.hotel.entitys.Vip;
import com.hotel.services.PermissionService;
import com.hotel.services.StaffService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;

import java.util.List;

@RestController
@Api(tags="login接口")//tags:说明信息
public class LoginController {
@Autowired
   private StaffService staffService;
    @Autowired
    private PermissionService permissionService;
    @ApiOperation(
            value = "登录",
            httpMethod = "POST",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @PostMapping("/login.do")
    public RestPOJO login(@RequestBody Staff staff) {
        RestPOJO restPOJO = new RestPOJO();
        Staff loginStaff = staffService.getStaffByNameAndPwd(staff.getStaff_telephone(),staff.getStaff_password());
        List<Integer> list = permissionService.selPerBySid(staff.getStaff_telephone());
        System.out.println(list);
        System.out.println(loginStaff);
        if (loginStaff != null) {
            restPOJO.setStatus(1000);
            restPOJO.setMessage("登录成功");
            restPOJO.setData(list);
        }else{
            restPOJO.setStatus(1001);
            restPOJO.setMessage("登录失败");
        }
        return restPOJO;
    }
    @PostMapping("/index/change")
    public RestPOJO updateLogin(@RequestBody Staff staff) {
        RestPOJO restPOJO = new RestPOJO();
        int loginStaff1 = staffService.updateLogin(staff);
        System.out.println(loginStaff1);
        if (loginStaff1 != 0) {
            restPOJO.setStatus(1000);
            restPOJO.setMessage("修改成功");
            return restPOJO;
        }else{
            restPOJO.setStatus(1001);
            restPOJO.setMessage("修改失败");
        }
        return restPOJO;
    }
    @GetMapping("/index/{id}")
    public RestPOJO getStaffById(@PathVariable("id") Integer staff_id){
        RestPOJO restPOJO = new RestPOJO();
        Staff staff = staffService.getStaffById(staff_id);
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("staff",staff);
        restPOJO.setData(map);
        return restPOJO;
    }

}





















